'''
get post
'''

import requests,json
from autoTest_BRTC_API.utils.readFile import read_yaml
from autoTest_BRTC_API.utils.log_util import logger

class Req():
    def __init__(self):
        self.req = requests.session()
        self.root_url = read_yaml('common.yaml')['root_url']


    def excute_request(self,req,method,url,headers=None,**kwargs):
        logger.debug((f"接口的地址是: \n {self.root_url+url}"))
        logger.debug((f"接口的请求方式是: \n {method}"))
        logger.debug((f"接口的请求头是: \n {json.dumps(headers,indent=4,ensure_ascii=False)}"))
        logger.debug((f"接口的请求参数是: \n {json.dumps(kwargs,indent=4)}"))

        try:
            if method == "GET":
                res = req.get(url=self.root_url+url,headers=headers,**kwargs)
                # 如果返回的http状态码不是200，就会报错
                res.raise_for_status()

            elif method == "POST":
                res = req.post(url=self.root_url + url, headers=headers, **kwargs)
                # 如果返回的http状态码不是200，就会报错
                res.raise_for_status()
            elif method == "PUT":
                res = req.put(url=self.root_url + url, headers=headers, **kwargs)
                # 如果返回的http状态码不是200，就会报错
                res.raise_for_status()
            return res
        except Exception as e:
            logger.error(f"脚本错误信息如下:{e}")


            # self.req.request("GET",url=url, headers=header, **kwarges)